﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using com.echonest.api.v4;

namespace Rename
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            if (File.Exists("developer_key.txt"))
            {
                this.developerKeyTextBox.Text = File.ReadAllText("developer_key.txt");
            }
        }

        private void analyzeButton_Click(object sender, EventArgs e)
        {
            var api = new EchoNestAPI(this.developerKeyTextBox.Text);
            var track = api.uploadTrack(new java.io.File(this.musicFileTextBox.Text), true);
            Track.AnalysisStatus status = track.waitForAnalysis(180000);
            if (status == Track.AnalysisStatus.COMPLETE)
            {

                var analysys = track.getAnalysis();
                var known = api.getKnownTrack(track.getAudioMD5());
                resultTextBox.Text = known.getTitle()+known.getArtistName()+ known.ToString();
            }
            else
            {
                resultTextBox.Text = status.ToString();
            }

        }
    }
}
